﻿<m:MetroWindow x:Class="mentalmath.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:s="clr-namespace:mentalmath"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:xwpft="http://schemas.xceed.com/wpf/xaml/toolkit" Icon="mentalmath-logo.png"
        xmlns:m="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro" Background="White" SizeToContent="WidthAndHeight" KeyDown="input_KeyDown"
        Title="mentalmath" ResizeMode="NoResize" DataContextChanged="Window_DataContextChanged">
    <Window.Resources>
        <Storyboard x:Key="sok" >
            <ColorAnimation Storyboard.TargetProperty="Color" Storyboard.TargetName="bgrectok" Duration="0:0:0.1" From="#FF41E141" AutoReverse="True" To="#FF80FF80" />
        </Storyboard>
        <Storyboard x:Key="snok" >
            <ColorAnimation Storyboard.TargetProperty="Color" Storyboard.TargetName="bgrectnok" Duration="0:0:0.1" From="#FFE14141" To="#FFFF8080" AutoReverse="True" />
       </Storyboard>
        <BooleanToVisibilityConverter x:Key="b2vc" />
        <s:InverseBooleanConverter x:Key="ibc" />
    </Window.Resources>
    <Border BorderBrush="#FF41B1E1" BorderThickness="1">
    <Grid>
        <Grid>  
            <Grid.RowDefinitions>
                <RowDefinition Height="auto" />
                    <RowDefinition Height="auto" />
                    <RowDefinition Height="*" />
            </Grid.RowDefinitions>
                <ProgressBar Maximum="{Binding CountdownTotal}" Value="{Binding Countdown.RemainingMilliseconds, Mode=OneWay}" Grid.Row="0" Visibility="{Binding Countdown.IsRunning,Converter={StaticResource b2vc}}" />
                <Grid Grid.Row="1" Visibility="{Binding HasAnswers,Converter={StaticResource b2vc}}">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="{Binding CorrectLength}" />
                    <ColumnDefinition Width="{Binding IncorrectLength}" />
                </Grid.ColumnDefinitions>
                    
                <Grid Grid.Column="0" >
                    <Grid.Background>
                        <SolidColorBrush x:Name="bgrectok" />
                    </Grid.Background>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="auto" />
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="auto" />
                    </Grid.ColumnDefinitions>
                    <TextBlock Text="{Binding NumCorrect}" Grid.Column="0" Margin="3,0,0,0" />
                    <TextBlock Text="{Binding NumCorrectPercent}" Grid.Column="2" Margin="0,0,3,0"/>
                </Grid>
                <Grid Grid.Column="1" >
                    <Grid.Background>
                        <SolidColorBrush x:Name="bgrectnok" />
                    </Grid.Background>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="auto" />
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="auto" />
                    </Grid.ColumnDefinitions>
                    <TextBlock Text="{Binding NumIncorrectPercent}" Grid.Column="0"  Margin="3,0,0,0" />
                    <TextBlock Text="{Binding NumIncorrect}" Grid.Column="2" Margin="0,0,3,0" />
                </Grid>
                    
                </Grid>            
            <Grid Grid.Row="2">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="auto" />
                        <RowDefinition Height="auto" />
                        <RowDefinition Height="auto" />
                        <RowDefinition Height="auto" />
                    </Grid.RowDefinitions>
                    <TextBlock Grid.Row="0" MinWidth="500" Margin="20,50,20,20" Text="{Binding CurrentExpression}" HorizontalAlignment="Center" FontSize="40" FontWeight="Bold" TextAlignment="Center" />
                <TextBlock Grid.Row="1" Margin="0,0,0,30" Text="= ?" HorizontalAlignment="Center" FontSize="30" FontWeight="Bold" />
                <TextBox Width="200" Grid.Row="2" Name="input" Text="{Binding Path=UserInput, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" FontSize="40" HorizontalAlignment="Center" HorizontalContentAlignment="Center" AutoWordSelection="False"  KeyDown="input_KeyDown"  Margin="0,0,0,20"/>
                    <TextBlock Grid.Row="3" Margin="5,10,5,5" VerticalAlignment="Top" HorizontalAlignment="Right" Text="Press * to start/stop countdown" />
                    <Expander Grid.Row="3" Margin="5" Header="Settings">
                    <Grid>
                        <StackPanel>
                        <StackPanel Orientation="Horizontal" Margin="10">
                            <CheckBox Content="+" IsChecked="{Binding Config.GeneratorConfig.Plus, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Margin="0,0,5,0" />
                            <CheckBox Content="-" IsChecked="{Binding Config.GeneratorConfig.Minus, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Margin="0,0,5,0" />
                            <CheckBox Content="×" IsChecked="{Binding Config.GeneratorConfig.Multiply, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Margin="0,0,5,0" />
                            <CheckBox Content="÷" IsChecked="{Binding Config.GeneratorConfig.Divide, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                        </StackPanel>
                            <StackPanel Margin="10" Orientation="Horizontal">
                                <TextBlock Text="Operations:   " />
                                <xwpft:IntegerUpDown Minimum="1" Maximum="4" Value="{Binding Config.GeneratorConfig.MinOperators}" />
                                <TextBlock Text="  to  "  />
                                <xwpft:IntegerUpDown Minimum="1" Maximum="4" Value="{Binding Config.GeneratorConfig.MaxOperators}" />
                            </StackPanel>
                            <StackPanel Orientation="Horizontal" Margin="10">
                                <TextBlock Text="Max. Result:   " />
                                <xwpft:IntegerUpDown Minimum="10"  Value="{Binding Config.GeneratorConfig.MaxResult}" Width="80" />
                                <TextBlock Text=" ,  Countdown-Interval:  " />
                                <xwpft:IntegerUpDown Minimum="1" IsEnabled="{Binding Countdown.IsRunning, Converter={StaticResource ibc}}"  Value="{Binding Config.GeneratorConfig.Countdown}"  Width="50" />
                                <TextBlock Text=" s" />
                                </StackPanel>
                                <StackPanel Orientation="Horizontal" Margin="10">
                                    <TextBlock Text="Profile:" Margin="0,0,10,0" VerticalAlignment="Center" />
                                    <ComboBox ItemsSource="{Binding Config.GeneratorProfiles}" Text="{Binding ProfileName}" DisplayMemberPath="Name" Width="150" IsEditable="True" SelectionChanged="ComboBox_Selected"/>
                                    <Button Command="{Binding SaveProfileCommand}">
                                        <Button.Content>
                                            <Grid>
                                                <Path Data="M0,1 L0,16 L16,16 L16,3 L13,0 L1,0" Fill="#41B1FF" />
                                                <Path Data="M2,1 L2,7 L13,7 L13,1" Fill="White" />
                                                <Path Data="M10,2 L10,6 L12,6 L12,2" Fill="#41B1FF" />
                                            </Grid>
                                        </Button.Content>
                                    </Button>
                                    <Button  Command="{Binding RemoveProfileCommand}">
                                        <Button.Content>
                                            <Grid>
                                                <Path Data="M1,0 L0,1 L7,8 L0,15 L1,16 L8,9 L15,16 L16,15 L9,8 L16,1 L15,0 L8,7" Fill="Red" />
                                            </Grid>
                                        </Button.Content>
                                    </Button>
                                </StackPanel>
                        </StackPanel>
                    </Grid>
                </Expander>
            </Grid>
        </Grid>
    </Grid>
    </Border>
</m:MetroWindow>
